<%@page import="com.crm.util.Pager"%>
<%@page import="com.crm.util.Constants"%>
<%@page import="com.crm.util.CrmUtil"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/page/public/taglib.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>分配资源</title>
	<%
		request.setAttribute("menu", 1);
	%>
	<meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <%@ include file="/WEB-INF/page/public/contentmeta.jsp"%>
    <link rel="stylesheet" href="<%=basePath%>plugins/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="<%=basePath%>css/global.css" media="all" />
    <link rel="stylesheet" href="<%=basePath%>plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="<%=basePath%>css/tab.css" media="all" />
</head>
<body>

<div class="admin-tab admin-user admin-transform">
    <div class="tab-condition">
        <form class="layui-form clefix" action="/customer/customerresourcesurl" method="post" id="transformform">
            <div class="layui-form-item">
            	<div class="layui-input-inline">
					<input type="text" name="keyWord" id="keyWord" class="layui-input" placeholder="请输入关键字"  style="width:100%" value="${pager.params.keyWord}"> 
	            </div>
	            <div class="layui-input-inline">
					<input type="text" name="address" id="address" class="layui-input" placeholder="请输入地区"  style="width:100%" value="${pager.params.address}"> 
	            </div>
            	<div class="layui-input-inline">
                    <select name="servicesign" id="servicesign" lay-filter="servicesign" class="typeclass">
                        <option value="">请选择标记</option>
                        <option value="-2" <c:if test="${pager.params.servicesign == -2}">selected</c:if>>全部</option>
                        <option value="0" <c:if test="${pager.params.servicesign == 0}">selected</c:if>>空号</option>
                        <option value="1" <c:if test="${pager.params.servicesign == 1}">selected</c:if>>已联系</option>
                        <option value="2" <c:if test="${pager.params.servicesign == 2}">selected</c:if>>未联系</option>
                        <option value="3" <c:if test="${pager.params.servicesign == 3}">selected</c:if>>无人接听</option>
                    </select>
                </div>
                <div class="layui-input-inline">
                    <select name="state" id="state"   class="typeclass">
                        <option value="">请选择成熟等级</option>
                         <option value="-2" <c:if test="${pager.params.state == -2}">selected</c:if>>全部</option>
                         <option value="4"  <c:if test="${pager.params.state == 4}">selected</c:if> >公共资源</option> 
                         <option value="0" <c:if test="${pager.params.state == 0}">selected</c:if>>最新资源</option> 
                          <option value="1" <c:if test="${pager.params.state == 1}">selected</c:if>>意向不明</option> 
                          <option value="2" <c:if test="${pager.params.state == 2}">selected</c:if>>意向明确</option>
                          <option value="3" <c:if test="${pager.params.state == 3}">selected</c:if>>意向强烈</option>
                          <option value="7" <c:if test="${pager.params.state == 7}">selected</c:if>>合作客户</option> 
                    </select>
                </div>
            	<input name="skipToPage" id="skipToPage"  type="hidden" value="${pager.pageNo}">
				<input type="hidden" id="pageNo" name="pageNo" value="${pager.pageNo}">
				<input type="hidden" id="totalPage" name="totalPage" value="${pager.totalPages}">
				<input type="hidden" id="pageSize" name="pageSize" value="${pager.pageSize}">
				<button class="layui-btn search" type="button" lay-submit="" lay-filter="search"><i class="layui-icon">&#xe615;</i>搜索</button>
            </div>
        </form>
        <div class="TM-tab-info">
        	<!-- <a class="layui-btn layui-btn-primary layui-btn-small active upinfo">上传资源</a>
        	<a class="layui-btn layui-btn-primary layui-btn-small active transall">+全部分配</a>
        	<a class="layui-btn layui-btn-primary layui-btn-small transsome">+部分分配</a>-->
        	<a class="layui-btn layui-btn-primary layui-btn-small getmydata"><i class="layui-icon">&#xe608;</i>获取</a>  
        	<a class="layui-btn layui-btn-primary layui-btn-small deletesome"><i class="layui-icon">&#xe640;</i>删除</a>
        	<a class="layui-btn layui-btn-primary layui-btn-small refreshbtn"><i class="layui-icon">&#x1002;</i>刷新</a>
        </div>
    </div>
    <div class="layui-field-box">
        <table class="site-table table-hover TM-user TM-table3">
            <thead>
            <tr>
                <th style="width:5%;"  ><input type="checkbox" id="selected-all"/></th>
                <th style="width:5%;" class="tips">姓名</th>
                <th style="width:10%;" class="tips">联系电话</th>
                <th style="width:10%;" class="tips">所属人</th>
				<th style="width:15%;" class="tips">证书及专业</th>
				<th style="width:10%;" class="tips">地址</th>
				<th style="width:10%;" class="tips">身份证</th>
				<th style="width:10%"  class="tips">成熟等级</th>
				<th style="width:10%;" class="tips">最新联系时间</th>
                <th style="width:15%;" class="tips">操作</th>
            </tr>
            </thead>
            <tbody>
            	<c:forEach var="obj" items="${pager.resultList}">
            		<tr data="${obj.id}">
	            		<td><input type="checkbox" name="select-all-cbox" value="${obj.id}"/></td>
	            		<td>${obj.cname}</td>
	            		<td>
	            			<c:if test="${obj.cinfo.isdel == 1 }">该资源已被删除</c:if>
	            			<c:if test="${obj.cinfo.isdel != 1}">${obj.tel}</c:if>
	            		</td>
	            		<td>${obj.cinfo.createusersname}</td>
	            		<td>${obj.technicalpost}</td>
	            		<td>${obj.address}</td>
	            		<td data="${obj.id}">${obj.idcard}</td>
	            		<td ><dic:cf value="${obj.state!=null?obj.state:obj.tempstate}" name="customer_state" type="1"/></td>
	            		<td >
	            			<c:if test="${obj.owntype != 1}">
	            				无
	            			</c:if>
	            			<c:if test="${obj.owntype == 1}">
	            				<c:if test="${fn:length(obj.cDynaicItem) > 0}">
									${obj.cDynaicItem.get(0).updatedate.substring(0,10)}
								</c:if>
								<c:if test="${fn:length(obj.cDynaicItem) < 1}">
									暂无联系记录
								</c:if>
	            			</c:if>
	            		</td>
	            		<td>
	            			<c:if test="${obj.owntype == 0 && obj.cinfo.isdel != 1}">
	            				<a href="#" class="layui-btn layui-btn-normal layui-btn-mini gjbtn" data="${obj.cusid}">跟进</a>
	            			</c:if>
	            			<c:if test="${obj.owntype == -1 && obj.cinfo.isdel != 1}">
	            				<a href="#" class="layui-btn layui-btn-normal layui-btn-mini lrbtn">录入</a>
	            			</c:if>
							<c:if test="${obj.owntype == 1 && obj.cinfo.isdel != 1}">
								<c:if test="${obj.cinfo.uid == sessionScope.user.id}">
									<a href="#" class="layui-btn layui-btn-normal layui-btn-mini gjbtn" data="${obj.cusid}">跟进</a>
								</c:if>
								<c:if test="${obj.cinfo.uid != sessionScope.user.id}">
									<a  href="javascript:;"  class="layui-btn layui-btn-normal layui-btn-mini askFor" data="${obj.cusid}" >索要</a>
								</c:if>
							</c:if>
							<a href="#" class="layui-btn layui-btn-normal layui-btn-mini bjbtn" data="${obj.id}" remdata="${obj.remark}" serdata="${obj.servicesign}">标记</a>
							<a href="#" class="layui-btn layui-btn-normal layui-btn-mini delete">删除</a>
	            		</td>
            		</tr>
            	</c:forEach>
            </tbody>
        </table>
        <div class="admin-table-page">
			<div   class="page" ><div class="layui-laypage"  ><span class="layui-laypage-total"><button type="button" class="layui-laypage-btn">共${pager.totalSize}条记录</button></span></div></div>
		</div>
        <div class="admin-table-page">
            <div id="page" class="page"></div>
        </div>
    </div>
    
</div>

<!-- 联系记录弹窗 -->
    <div class="addlxjl"  style="display: none;">
    	<form class="layui-form" id="tjlxjlForm" action="">
	      <div class="layui-form-item address" style="margin-top:10px">
	            <label class="layui-form-label">联系人： </label>
	            <div class="layui-input-block" style="width:60%">
	                  <select name="contact" id="contact"  lay-filter="contact">
	                    	<option value="">请选择</option>
	                 </select>
	            </div>
	        </div>
		     <div class="layui-form-item layui-form-text">
			    <label class="layui-form-label">备注：</label>
			    <div class="layui-input-block" style="width:60%">
			      <textarea id="remark" name="remark" placeholder="请输入内容" class="layui-textarea"></textarea>
			        <input name="id" id="jlid" type="hidden" value="0">
			    </div>
			 </div>
	    </form>
    </div>
    
    <!--索要弹窗 -->
<div id="TM-layui-askFor" style="display:none;">
    <div class="TM-ask-for" style="padding:10px 20px;">
        <h4 style="margin-bottom:10px;">备注</h4>
        <textarea name="" id="askforremark" cols="60" rows="5"></textarea>
    </div>
</div>


<!-- 客服联系弹窗 -->
<div class="kflxtcdiv" style="display:none;">
	<div style="margin-top: 10px;">
		<form action="" id="kflx_form"  class="layui-form" >
			<div class="layui-form-item">
				<label class="layui-form-label"><span>标记 : </span></label>
				<div class="layui-input-inline">
					<select name="state" id="bjstate" lay-filter="lay-filter">
						<option>请选择标记</option>
						<option value="0">空号</option>
						<option value="1">已联系</option>
						<option value="2">未联系</option>
						<option value="3">无人接听</option>
					</select>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label"><span>备注 : </span></label>
				<div class="layui-input-inline">
					<textarea placeholder="请输入内容" class="layui-textarea" id="bjremark" name="remark"></textarea>
				</div>
			</div>
			<input type="hidden"  id="lxid" name="id" value="">
		</form>
	</div>
</div>


<div class="Mask ZZmask"></div>

<script type="text/javascript">
	layui.use(['icheck','element','laypage','form','laydate'],function(){
		
		var $ = layui.jquery,
		layer = layui.layer,
		laypage = layui.laypage;
		var form = layui.form();
		form.render();
		
		//移上去有提示
		/* $(document).on("mouseover",".tips",function(){
			var text = "各位亲:</br>分配给你们的资源,如果原先在公共库的,那现在就已经在你们的资源库中了,可以直接跟进.</br>"+
			"如果觉得是垃圾客户,点击删除,那这个客户就会从你的库中回到公共库.</br>"+
			"如果原先资源已经在其他同事的库中,那你只能通过索要获取符合索要条件的资源</br>"+
			"如果原先资源不存在库中,那你可以点击录入将客户录入你的资源库."
			
			
			
			layer.tips(text, '.tips', {
				tips: [2, '#f7625e'],
				area:["500px"],
				time: 3500,
			});
		}); */
		
		
		
		$(".getmydata").on("click",function(){
			var totalPage = $("#totalPage").val();
			if(totalPage>5){
				layer.msg("数据少于6页时方可获取！",{icon: 2})
			}else{

	  			layer.confirm('确认获取资源吗？', {
		  			  btn: ['确定','取消'] //按钮
		  		}, function(){
		  			var index = layer.load(1); //换了种风格
		  			$.ajax({
		  				type : "post",
		  				url : "/customer/distributionsome",
		  				data : {startpage : 1 ,endpage : 5, uid : '${sessionScope.user.id}' , pagesize : 10 },
		  				dataType : "json",
		  				success : function(data){
		  					//关闭加载层
	  						layer.msg("资源获取成功",{icon:1},function(){
		  						window.location.reload();
		  					});
		  				}
		  			});
		  		}, function(){
		  		});
			}
		});
		
		
		//点击添加标记
		$(".bjbtn").on("click",function(){
			//清空输入框内容
			$("#lxid").val('');
			$("#bjstate").val('');
			$("#bjremark").text('');
			form.render();
			//获取参数
			var id = $(this).attr("data");
			var servicesign = $(this).attr("serdata");
			var remark = $(this).attr("remdata");
			//获取当前日期时间
			var myDate = new Date();    
	 		var dateTime = myDate.toLocaleDateString();
	 		if (remark != null || servicesign != null) {
				$("#bjstate").val(servicesign);
				$("#bjremark").text(remark+dateTime+":");
				form.render();
	 		} else {
	 			$("#bjremark").text(dateTime+":");
	 		}
	 		//打开弹窗
			layer.open({
				type:1,
				btn:['确定','取消'],
				btnAlign:'c',
				shadeClose:true,
				title:"标记",
				zIndex: 999,
				content: $(".kflxtcdiv"),
				area:['30%','50%'],
				yes: function(layero, index){
					var servicesign = $("#bjstate").val();
					var remark = $("#bjremark").val();
					$.ajax({
						type : "post",
						data : {id:id,servicesign:servicesign,remark:remark},
						url : "/customer/addtempsign",
						dataType:"json",
						success : function(data){
							layer.msg("标记成功",function(){
								window.location.reload();
							});
						}
					});
				}
			});
		});
		
		
		
		//点击全选
        $("#selected-all").on("click",function(){
        	if ($("#selected-all").is(":checked")){
        		$("[name='select-all-cbox']").prop("checked",true);
        	} else {
        		$("[name='select-all-cbox']").prop("checked",false);
        	}
        });
		
		//点击删除选中的
		$(".deletesome").on("click",function(){
			//看看有哪些被选中的
			var ids;
    		//利用.each获取
			$("input:checkbox[name='select-all-cbox']:checked").each(function(i){
				if (i == 0) {
					ids = $(this).val();
				} else {
					ids += ","+$(this).val();
				}
			});
    		if (ids == null || ids == '') {
    			layer.msg("请选择一条或多条资源");
    			return false;
    		}
    		$.ajax({
				type : "post",
				data : {ids : ids},
				url : "/customer/deletecustemp",
				dataType : "json",
				success : function(data){
					layer.msg("删除成功",{icon:1},function(){
						window.location.reload();
					});
				}
			})
		});
		
		
		
		
		
		//点击删除
		$(".delete").on("click",function(){
			var ids = $(this).parent().parent().attr("data");
			layer.confirm('确认删除吗？', {
				btn: ['确定','取消'] //按钮
			}, function(){
				$.ajax({
					type : "post",
					data : {ids : ids},
					url : "/customer/deletecustemp",
					dataType : "json",
					success : function(data){
						layer.msg("删除成功",{icon:1},function(){
							window.location.reload();
						});
					}
				})
			}, function(){
			});
		});
		
		//点击录入
		$(".lrbtn").on("click",function(){
			var id = $(this).parent().parent().attr("data");
			parent.layer.open({
   			  type: 2, 
   			  title:"录入信息",
   			  area: ['95%', '95%'],
   			  content: "/customer/changetemptocustomer"+id,
   		 	});
			window.location.reload();
		});
		
		//点击跟进
		$(".gjbtn").on("click",function(){
			var id = $(this).parent().parent().attr("data");
			var cusid = $(this).attr("data");
			$.ajax({
				type : "post",
 		 		url : "/customer/customerinfoajax",
 		 		data : {id:cusid},
 		 		dataType : "json",
 		 		async : false,
 		 		success : function(data){
 		 			if (data != null) {
 		 				var html ="";
 	 		 		    var contacts =	data.contactsItem;
 	 		 		    var cname = data.cname; 
 	 		 		    if(contacts!=null&&contacts.length>0){
 	 		 		    	for(var i =0;i<contacts.length;i++){
 	 		 		    		 html+="<option value='"+contacts[i].id+"'>"+contacts[i].name+"(电话："+contacts[i].tel+")</option>";
 	 		 		    	} 
 	 		 		    	$("#contact").html(html);
 	 		 		    }else{
 	 		 		    	$("#contact").html("<option value=''>请选择联系人</option>");
 	 		 		    }
 	 		 			form.render(); 
 	 		 			 layer.open({
 		                       type:1,
 		                       content:$('.addlxjl'),
 		                       btn:['确定','取消'],
 		                       btnAlign:'c',
 		                       shadeClose:true,
 		                       title:cname+'添加联系记录',
 		                       area:['600px','300px'],
 		                       maxWidth:800,
 		                       yes: function(layero, index){
 			                   		var ccuid = $("#contact").val();
 			                       	var remark = $("#remark").val();
 			                       	//var cusid = id;
 			                       	//var type = $("#customertype").val();
 			                       	//var state = $("#customerstate").val();
 			                       	//var pageNo = $("#pageNo").val();
 			                       	//var url = "/customer/entman/ty"+type+"_st"+state+"_p"+pageNo;
 			                       	$.ajax({
 			                       		type : "post",
 			                       		url : "/customer/addcontactsdynamicinfo",
 			                       		data : {ccuid:ccuid,remark:remark,cusid:cusid},
 			                       		dataType : "json",
 			                       		success : function(data){
 			                       			if (data == 1) {
 			                       				layer.closeAll();
 			                       				layer.msg("添加联系记录成功",{icon: 1},function(){
 			                       					window.location.reload();
 			                       				});
 			                       			} else { 
 			                       				layer.msg("添加联系记录失败",{icon: 2});
 			                       			}
 			                       		}
 			                       	});
 		                       }
 	 	                 });
 		 			} else {
 		 				layer.msg("无权添加联系记录",{icon: 2})
 		 			}
 		 		}
			})
			
		});
		
		//索要弹窗
        $('.askFor').on('click',function(){
        	var id =$(this).attr("data"),remark =$("#askforremark").val();
            layer.open({
                type:1,
                content:$('#TM-layui-askFor').html(),
                btn:['确定','取消'],
                btnAlign:'c',
                shade: [.6,'#000'],
                shadeClose:true,
                title:'索要',
                area:'auto',
                maxWidth:800,
                yes: function(layero, index){
                	$.ajax({
        				type : "post",
        				url : "/customer/claimsave",
        				data : {cusid:id,remark:remark},
        				dataType : "json",
        				success : function(data){
        					if(data=="1"){
        						 layer.close(layero);
        						 layer.msg("索要成功",{icon: 1},function(){
            						//window.location.reload();
            					});
        					}else{
        						layer.msg("索要失败",{icon: 2} );
        					} 
        				}
        			});
                	
                }
            });
        });
		
		//点击搜索
		$(".search").on("click",function(){
			$("#skipToPage").val(1);
			$("#transformform").submit();
		});
		
		
		//分页
		var pageNo = $("#pageNo").val();
    	var totalPage = $("#totalPage").val();
    	laypage({
            cont: 'page',
            curr: pageNo//'${pager.pageNo}'
            ,pages: totalPage//'${pager.totalPages}' //总页数
            ,
            groups: 5 //连续显示分页数
            ,
            skip: true,
            jump: function(obj, first) {
                //得到了当前页，用于向服务端请求对应数据
                var curr = obj.curr;
                if(!first) {
                	$("#skipToPage").val(curr);
                	$("#transformform").submit();
                }
            }
        }); 
	});
</script>

</body>
</html>